package com.github.pig.admin.service.zhgl.propertyassess.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.admin.model.zhgl.propertyassess.AssessDetaiEntity;
import com.github.pig.admin.model.zhgl.propertyassess.PropertyAssess;
import com.github.pig.admin.mapper.zhgl.propertyassess.PropertyAssessMapper;
import com.github.pig.admin.model.zhgl.propertyassess.PropertyAssessCount;
import com.github.pig.admin.service.zhgl.propertyassess.IPropertyAssessService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.util.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 物业人员评价表 服务实现类
 * </p>
 *
 * @author xiaosa
 * @since 2018-06-11
 */
@Service
public class PropertyAssessServiceImpl extends ServiceImpl<PropertyAssessMapper, PropertyAssess> implements IPropertyAssessService {


    @Autowired
    private PropertyAssessMapper propertyAssessMapper;

    @Override
    public Page selectTotal(Page page,PropertyAssessCount propertyAssessCount) {
        List<PropertyAssessCount> result =  propertyAssessMapper.selectTotal(page,propertyAssessCount);
        page.setRecords(result);
        return page;
    }

    @Override
    public Page detailPage(Page page,Integer propertyId,String assessType,String communityId) {
        List<AssessDetaiEntity> result =   propertyAssessMapper.getDetailData(page,propertyId,assessType,communityId);
        page.setRecords(result);
        return page;
    }

    @Override
    public AjaxJson getSumComments(PropertyAssessCount propertyAssessCount){

        // 定义评论总数sumPls
        Integer sumPls = 0 ;
        AjaxJson json = new AjaxJson();
        try {
            List<PropertyAssessCount> list = propertyAssessMapper.selectTotal(propertyAssessCount);
            // 遍历list获取到物业评价总数
            for (PropertyAssessCount item:list) {
                // 获取到评论数
                Integer pls = item.getPls();
                sumPls+=pls;
            }
            json.setObj(sumPls);
            json.setSuccess(true);
            json.setMsg("获取评论总数成功");
        }catch (Exception e){
            System.out.println(e);
            json.setMsg("获取评论总数失败");
            json.setSuccess(false);
        }

        return json;
    }
}